<template>
  <div class="number-range" :style="{width: rangeWidth}">
    <el-input
      v-model="start"
      :placeholder="startPlaceholder"
      @input="dataChange"
    />
    <div class="range-separator">{{ rangeSeparator }}</div>
    <el-input
      v-model="end"
      :placeholder="endPlaceholder"
      @input="dataChange"
    />
  </div>
</template>

<script>

export default {
  name: 'NumberRange',
  model: {
    prop: 'rangeData',
    event: 'input'
  },
  props: {
    rangeData: {
      type: Array,
      default() {
        return []
      }
    },
    rangeWidth: {
      type: String,
      default() {
        return '228px'
      }
    },
    rangeSeparator: {
      type: String,
      default() {
        return '至'
      }
    },
    startPlaceholder: {
      type: String,
      default() {
        return ''
      }
    },
    endPlaceholder: {
      type: String,
      default() {
        return ''
      }
    }
  },
  data() {
    return {
      start: '',
      end: ''
    }
  },
  computed: {

  },
  watch: {
    rangeData: {
      handler(newValue, oldValue) {
        this.start = this.rangeData[0] || ''
        this.end = this.rangeData[1] || ''
      },
      deep: true
    }
  },
  mounted() {},
  methods: {
    dataChange() {
      this.$emit('input', [this.start, this.end])
    }
  }
}
</script>

<style scoped lang="scss">
.number-range {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  background-color: #ffffff;
  background-image: none;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  .el-input {
    flex: auto;
  }
  .range-separator {
    flex: none;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 12px;
    color: #303133;
  }
  ::v-deep .el-input input {
    border: 0;
    width: 100% !important;
    text-align: center;
  }
}
</style>
